package com.hassean.we.admin.common.util;

import com.hassean.we.admin.common.constant.CommonConstant;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * Created by yajun on 2019/4/21.
 */
public class PrepareCall {
    /**
     * 获取数据库连接
     *
     * @return Connection对象
     */
    public Connection getConnection() {
        Connection conn = null;   //数据库连接
        try {
            Class.forName("com.mysql.jdbc.Driver"); //加载数据库驱动，注册到驱动管理器
            /*数据库链接地址*/
            String url = CommonConstant.jdbdUrl;
            String username = CommonConstant.username;
            String password = CommonConstant.password;
            /*创建Connection链接*/
            conn = DriverManager.getConnection(url, username, password);

        } catch (ClassNotFoundException e) {

            e.printStackTrace();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return conn;  //返回数据库连接

    }

}
